# $Id: PKGBUILD 87018 2013-03-25 19:17:00Z bpiotrowski $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=pyrss
pkgver=0.9.9.1
pkgrel=12
pkgdesc="jabber rss transport"
arch=(any)
url="http://code.google.com/p/pyrss/"
license=("GPL")
depends=(python2 python2-pyxmpp python2-feedparser mysql-python)
backup=(etc/ejabberd/pyrss.xml)
source=(http://archlinux-stuff.googlecode.com/files/pyrss-$pkgver.tar.bz2
	pyrss.rc
	pyrss.service)
md5sums=('3f48f3b7f36c2c588b8d55a5841482ab'
         '67e9a1de034bc55397d635d1072b0a03'
         '1fbbcc50f4b8ca5d8db1d3adffb5e42e')

package() {
    cd $srcdir

    # python2 fix
    for file in $(find . -name '*.py' -print); do
        sed -i 's_^#!.*/usr/bin/python_#!/usr/bin/python2_' $file
        sed -i 's_^#!.*/usr/bin/env.*python_#!/usr/bin/env python2_' $file
    done
    sed -i 's|python pyrss.py|python2 pyrss.py|g' $pkgname-$pkgver/start.py
    patch $pkgname-$pkgver/pyrss.py <<EOF
--- pyrss.py.org	2005-08-30 23:54:40.000000000 +0400
+++ pyrss.py	2012-05-03 17:08:39.000000000 +0400
@@ -10,11 +10,6 @@
 
 # Added by St. Hermann <sh@sourcecode.de>
 
-try: 
-    import psyco
-    psyco.full()
-finally:
-    pass
 from optparse import OptionParser
 import sys
 import logging
EOF

    install -d -m0755 $pkgdir/usr/lib
    cp -r $pkgname-$pkgver $pkgdir/usr/lib
    mv $pkgdir/usr/lib/$pkgname-$pkgver $pkgdir/usr/lib/$pkgname

    install -d -m0755 $pkgdir/etc/ejabberd
    mv $pkgdir/usr/lib/$pkgname/pyrss.xml $pkgdir/etc/ejabberd/pyrss.xml
    install -D -m0755 pyrss.rc $pkgdir/etc/rc.d/pyrss
    sed -i 's#/etc/jabber/pyrss.xml#/etc/ejabberd/pyrss.xml#' $pkgdir/usr/lib/$pkgname/contrib/auth.py
    sed -i 's#/etc/jabber/pyrss.xml#/etc/ejabberd/pyrss.xml#' $pkgdir/usr/lib/$pkgname/pyrss.py

    install -Dm0644 $srcdir/$pkgname.service $pkgdir/usr/lib/systemd/system/$pkgname.service
}
